package vip.xiaonuo.hontu.listener.handle;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import org.springframework.stereotype.Service;
import vip.xiaonuo.hontu.listener.handle.impl.ClusterDataHandleService;
import vip.xiaonuo.hontu.listener.handle.impl.SecurityPushDataHandleService;
import vip.xiaonuo.hontu.listener.handle.impl.TransPushDataHandleService;
import vip.xiaonuo.hontu.listener.handle.model.HongTuPushData;
import vip.xiaonuo.modular.htpushdata.entity.HtPushData;
import vip.xiaonuo.modular.htpushdata.service.HtPushDataService;

import javax.annotation.Resource;

@Service
public class PushDataHandleCenter {

    @Resource
    private HtPushDataService pushDataService;

    @Resource
    private SecurityPushDataHandleService securityPushDataHandleService;

    @Resource
    private TransPushDataHandleService transPushDataHandleService;

    @Resource
    private ClusterDataHandleService clusterDataHandleService;

    private HandleService getStrategy(HtPushData data) {
        String content = data.getValue();
        HongTuPushData pushData = JSON.parseObject(content,HongTuPushData.class);
        if(ObjectUtil.equal( pushData.getBusiType(),"1")){ // 安防记录
            return securityPushDataHandleService;
        }else if(ObjectUtil.equal( pushData.getBusiType(),"5")){ // 通行识别记录
            return transPushDataHandleService;
        }else if (ObjectUtil.equal(pushData.getBusiType() , "99")){ // 聚类结果记录
            return clusterDataHandleService;
        }else {
            return null;
        }
    }

    public void handleData(HtPushData data){
        HandleService strategy = this.getStrategy(data);
        if(strategy==null){
            data.setStatus(1);
            data.setFailReason("暂不处理该类型数据");
            pushDataService.updateById(data);
        }else{
            strategy.handle(data);
        }
    }



}
